/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Interfaz;

import bases.Bases;
import java.awt.Dimension;
import java.awt.Graphics;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author mikygonka
 */
public class Agencia extends javax.swing.JFrame {
 Bases bd=new Bases();
 DefaultTableModel tabla;
 DefaultComboBoxModel lista1;
    /**
     * Creates new form Agencia
     */
    public Agencia() {
        initComponents();
        bd.conectar("agencia");
        this.setBounds(500,250, 767, 485);
        
        
        lista1=new DefaultComboBoxModel();
        jComboBox1.setModel(lista1);
        
        String []tablas={"Clientes","Destinos","Escalas","Reservas","Viajes","ViajesOrganizados"};
        for (int i = 0; i < tablas.length; i++) {
            lista1.addElement(tablas[i]);
        }
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jComboBox1 = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(null);

        jPanel1.setBackground(new java.awt.Color(240, 202, 205));

        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(27, 27, 27)
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 586, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(17, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel1);
        jPanel1.setBounds(80, 30, 600, 390);

        jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Users\\pri\\Documents\\NetBeansProjects\\swing8\\rosas.jpg")); // NOI18N
        jLabel1.setText("jLabel1");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 780, 470);

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        jMenu2.setText("Edit");

        jMenuItem1.setText("Añadir Reservas");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuItem2.setText("Añadir Cliente");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        jMenuItem3.setText("Añadir Destino");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem3);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        
        if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("Destinos")){
            Object [][]datos=bd.listarOrdenadoDestinos("Destinos","CodDest","Desc");
        
        String []titulo={"CodDestino","Ciudad","Hora llegada","Medio trans"};
        tabla=new DefaultTableModel(datos,titulo);
        jTable1.setModel(tabla);
        }else if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("Clientes")){
            Object [][]datos=bd.listarOrdenadoClientes("Clientes","CodCliente","Desc");
        
        String []titulo={"CodCliente","Nombre","Ciudad","Localidad","Provincia"};
        tabla=new DefaultTableModel(datos,titulo);
        jTable1.setModel(tabla);
        }
        else if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("Escalas")){
            Object [][]datos=bd.listarOrdenadoEscalas("Escalas","CodViaje","Desc");
        
        String []titulo={"Codviaje","codDest","Norden"};
        tabla=new DefaultTableModel(datos,titulo);
        jTable1.setModel(tabla);
        }
        else if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("Reservas")){
            Object [][]datos=bd.listarOrdenadoReservas("reservas","CodCliente","Desc");
        
        String []titulo={"CodLciente","CodViaje","NPerso","FechaReserva","FechaSal"};
        tabla=new DefaultTableModel(datos,titulo);
        jTable1.setModel(tabla);
        }
        else if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("Viajes")){
            Object [][]datos=bd.listarOrdenadoViajes("Viajes","CodViaje","Desc");
        
        String []titulo={"CodViaje","Descripcion"};
        tabla=new DefaultTableModel(datos,titulo);
        jTable1.setModel(tabla);
        }
        else if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("ViajesOrganizados")){
            Object [][]datos=bd.listarOrdenadoViajesOrganizados("ViajesOrganizados","CodViaje","Desc");
        
        String []titulo={"CodViaje","NPerso","FechaSal","FechaLlega","Precio"};
        tabla=new DefaultTableModel(datos,titulo);
        jTable1.setModel(tabla);
        }
    }//GEN-LAST:event_jComboBox1ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
         new NReservas(new javax.swing.JFrame(),true).setVisible(true);
        
            Object [][]datos=bd.listarOrdenadoReservas("reservas","CodCliente","Desc");
        
        String []titulo={"CodLciente","CodViaje","NPerso","FechaReserva","FechaSal"};
        tabla=new DefaultTableModel(datos,titulo);
        jTable1.setModel(tabla);// TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        new NClientes(new javax.swing.JFrame(),true).setVisible(true);
        Object [][]datos=bd.listarOrdenadoClientes("Clientes","CodCliente","Desc");
        
        String []titulo={"CodCliente","Nombre","Ciudad","Localidad","Provincia"};
        tabla=new DefaultTableModel(datos,titulo);
        jTable1.setModel(tabla);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        new NDestinos(new javax.swing.JFrame(),true).setVisible(true);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Agencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Agencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Agencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Agencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Agencia().setVisible(true);
            }
        });
    }
    


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
